<script type="text/javascript">
	var i = 0, getOptionValueRow = function() {
		return {
			id:'',
			nodeId : "1",
			target : "目标名称"
		};
	};
	function addComponentNode() {
		componentNodeList.datagrid("appendRow", getOptionValueRow());
	}
	function removeComponentNode() {
		var rows = componentNodeList.datagrid('getChecked');
		printLog(rows);
	    if (rows&&rows.length>0){
	        $.messager.confirm('询问','你确认要删除记录吗?',function(r){
	            if (r){
	            	for (var i = rows.length - 1; i >= 0; i--) {
	            		printLog(rows[i]);
	            		var index = componentNodeList.datagrid('getRowIndex', rows[i]);
	            		componentNodeList.datagrid('deleteRow', index);
	            	}
	            }
	        });
	    }else {
	    	showMsg("请选择操作记录.");
	    }
    }
	
	function addDeviceLinkInfo() {
		var component = {
// 			id:$('#deviceLinkId').val(),
// 			lid:,$('#deviceLinkLid').combobox('getValue');
// 			ltype:$('#deviceLinkLid').val(),
			addr:$('#sbaddr').val(),
			channel:$('#sbchannel').val()
		};
		printLog('--------');
		if(selectTypeVal=='music') {
			component.volume = $('#musicVolume').val();
			component.power = $('#musicPower').combobox('getValue');
			component.input = $('#musicInput').val();
			component.ch = $('#musicCh').val();
			component.item = $('#musicItem').combobox('getValue');
		}else if(selectTypeVal=='tv') {
			component.volume = $('#tvVolume').val();
			component.power = $('#tvPower').combobox('getValue');
			component.input = $('#tvInput').val();
			component.ch = $('#tvCh').val();
			component.item = $('#tvItem').combobox('getValue');
		}else if(selectTypeVal=='ac') {
			component.power = $('#acPower').combobox('getValue');
			component.mode = $('#acMode').combobox('getValue');
			component.fan = $('#acFan').combobox('getValue');
			component.temp = $('#acTemp').val();
		}else if(selectTypeVal=='dimmer') {
			component.value = $('#dimmerValue').val();
			component.status = $('#dimmerStatus').combobox('getValue');
			component.delay = $('#dimmerDelay').val();
			component.freq = $('#dimmerFreq').val();
		}else if(selectTypeVal=='node') {
			component.type = $('#nodeType').combobox('getValue');
			component.status = $('#nodeStatus').combobox('getValue');
			component.delay = $('#nodeDelay').val();
			component.freq = $('#nodeFreq').val();
		}
		
		printLog(component);
    	var deviceLinkInfo = {
    		id:$('#deviceLinkId').val(),
    		lid:$('#deviceLinkLid').val(),
    		ltype:selectTypeVal,
    		addr:$('#sbaddr').val(),
			channel:$('#sbchannel').val(),
    		component:component
    	};
    	printLog(deviceLinkInfo);
    	jmaxAjax("deviceLink.do?saveDeviceLinkAndComponent",{data:JSON.stringify(deviceLinkInfo)},function(result) {
    		if('${isAdd!}'=='true') {
    			deviceLink_selectlist.datagrid("appendRow", result.obj);
    		}else {
    			deviceLink_selectlist.datagrid("updateRow", {index:${rowIndex!0},row:result.obj});
    		}
    	
//     		updateRow
//     		reloadConfigDevice();
        },true);
    	
	}
	var selectTypeVal = "${(deviceLinkItem.ltype)!}";
	function selectDeviceLinkType(value) {
		$('.musicField').hide();
		$('.tvField').hide();
		$('.acField').hide();
		$('.dimmerField').hide();
		$('.nodeField').hide();
		$('.'+value.value+'Field').show();
		selectTypeVal = value.value;
	}
	$('.${(deviceLinkItem.ltype)!}Field').show();
	
	function selectNodeType(value) {
		$('#nodeStatus').combobox("clear").combobox('reload','common.do?loadComboBox&key='+value.value+'_STATUS');
		//根据不同节点类型控制不同的显示
		isShowLightNode(value.value);
	}
	function isShowLightNode(nodeType) {
		if(nodeType!='LIGHTS') {
			$('#lightNode').hide();
		}else {
			$('#lightNode').show();
		}
	}
</script>
<div class="easyui-layout" data-options="fit:true">
	<div data-options="region:'center',border:false">
		<table cellpadding="5">
			<input id="deviceLinkId" name="id" type="hidden" value="${(deviceLinkItem.id)!}" />
			<tr>
				<td width="88px">设备类型:</td>
				<td width="200px">
					<@eu.comboBox id="deviceLinkLtype" url="common.do?loadComboBox&key=COMPONENT_TYPE&value=${(deviceLinkItem.ltype)!}" name="ltype" required="true" onSelect="selectDeviceLinkType(value)"/>
				</td>
				<td width="88px;">设备名称:</td>
				<td width="200px">
					<input id="deviceLinkLid" name="lid"  class="easyui-validatebox textbox" data-options="required: true" value="${(deviceLinkItem.lid)!}"/>
				</td>
			</tr>
			
			<tr>
				<td>
					设备地址
				</td>
				<td>
					<input name="addr" id="sbaddr" class="easyui-validatebox textbox" data-options="required: true" value="${(component.addr)!}"/>
				</td>
				<td>设备通道:</td>
				<td>
					<input name="channel" id="sbchannel" style="width:160px;" class="easyui-numberspinner" data-options="min:0,max:255" value="${(component.channel)?default(0)}" />  
				</td>

			</tr>
			<tr class="musicField" style="display: none;">
				<td>开关:</td>
				<td>
					<@eu.comboBox id="musicPower" url="common.do?loadComboBox&key=COM_POWER&value=${(component.power)?default(\"off\")}"  />
				</td>
				<td>
					音量
				</td>
				<td>
					<input name="volume" id="musicVolume" value="${(component.volume)?default(50)}" class="easyui-slider" data-options="showTip:true,rule:[0,'|',25,'|',50,'|',75,'|',100]" />
				</td>
				<td>输入源选择:</td>
				<td>
					<input id="musicInput"  name="input" class="easyui-numberspinner" data-options="min:0,max:10" value="${(component.input)?default(0)}" />  
				</td>
				<td>频道:</td>
				<td>
					<input name="ch" id="musicCh" class="easyui-numberspinner" data-options="min:0,max:255" value="${(component.ch)?default(0)}" />  
				</td>
			</tr>
			<tr class="musicField" style="display: none;">
				<td>节目:</td>
				<td>
					<@eu.comboBox id="musicItem" url="common.do?loadComboBox&key=PROGRAM_ITEM&value=${(component.item)?default(\"next\")}" />
				</td>
			</tr>
			
			
			<tr class="tvField" style="display: none;">
				
				<td>开关:</td>
				<td>
					<@eu.comboBox id="tvPower" url="common.do?loadComboBox&key=COM_POWER&value=${(component.power)?default(\"off\")}" />
				</td>
				<td>
					音量
				</td>
				<td>
					<input name="volume" id="tvVolume" value="${(component.volume)?default(50)}" class="easyui-slider" data-options="showTip:true,rule:[0,'|',25,'|',50,'|',75,'|',100]" />
				</td>
				<td>输入源选择:</td>
				<td>
					<input id="tvInput"  name="input" class="easyui-numberspinner" data-options="min:0,max:10" value="${(component.input)?default(0)}" />  
				</td>
				<td>频道:</td>
				<td>
					<input name="ch" id="tvCh" class="easyui-numberspinner" data-options="min:0,max:255" value="${(component.ch)?default(0)}" />  
				</td>
			</tr>
			<tr class="tvField" style="display: none;">
				<td>节目:</td>
				<td>
					<@eu.comboBox id="tvItem" url="common.do?loadComboBox&key=PROGRAM_ITEM&value=${(component.item)?default(\"next\")}"  />
				</td>
			</tr>
			<tr class="acField" style="display: none;">
				<td>开关:</td>
				<td>
					<@eu.comboBox id="acPower" url="common.do?loadComboBox&key=COM_POWER&value=${(component.power)?default(\"off\")}"  />
				</td>
			  <td>
			  	模式
			  </td>
			  <td>
			      <@eu.comboBox id="acMode" url="common.do?loadComboBox&key=AC_MODE&value=${(component.mode)?default(\"auto\")}"  />
			  </td>
			  <td>
			  	风速
			  </td>
			  <td>
			      <@eu.comboBox id="acFan" url="common.do?loadComboBox&key=AC_FAN&value=${(component.fan)?default(\"low\")}"  />
			  </td>
			  <td>
			  	温度
			  </td>
			  <td>
			  	<input id="acTemp" class="easyui-numberspinner" data-options="min:16,max:3" value="${(component.tset)?default(20)}" />  
			  </td>
			</tr>
			<tr class="dimmerField" style="display: none;">
				<td>
					状态
				</td>
				<td>
					<@eu.comboBox id="dimmerStatus" url="common.do?loadComboBox&key=DIMMER_STATUS&value=${(component.status)?default(\"off\")}"  />
				</td>
				<td>
					亮度
				</td>
				<td>
					<input name="value" id="dimmerValue" class="easyui-slider" value="${(component.value)?default(50)}" data-options="showTip:true,rule:[0,'|',25,'|',50,'|',75,'|',100]" />
				</td>
				<td>闪烁频率:</td>
				<td>
					<input id="dimmerFreq" class="easyui-numberspinner" data-options="min:0,max:255" value="${(component.freq)?default(1)}" />秒/次 
				</td>
				<td>延迟时间:</td>
				<td>
					<input id="dimmerDelay" class="easyui-numberspinner" data-options="min:0,max:255" value="${(component.delay)?default(0)}" />秒  
				</td>
				
			</tr>
			<tr class="nodeField" style="display: none;">
				<td>
					节点类型：
				</td>
				<td>
					<@eu.comboBox id="nodeType" url="common.do?loadComboBox&key=NODE_TYPE&value=${(component.type)!}"  onSelect="selectNodeType(value)"/>
				</td>
				<td>
					状态
				</td>
				<td>
					<@eu.comboBox id="nodeStatus" url="common.do?loadComboBox&key=${(component.type)!}_STATUS&value=${(component.status)?default(\"off\")}"  />
				</td>
			</tr>
			<tr id="lightNode" class="nodeField" style="display: none;">
				<td>闪烁频率:</td>
				<td>
					<input id="nodeFreq" style="width:160px;" class="easyui-numberspinner" data-options="min:0,max:255" value="${(component.freq)?default(1)}" />秒/次 
				</td>
				<td>延迟时间:</td>
				<td>
					<input id="nodeDelay" style="width:160px;" class="easyui-numberspinner" data-options="min:0,max:255" value="${(component.delay)?default(0)}" />秒
				</td>
			</tr>
		</table>
	</div>
</div>
<script type="text/javascript">
	isShowLightNode('${(component.type)!}');
</script>
